////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   CODE
// AUTHOR           :   Saint Peng
// DATE CREATE      :   2006/01/05
// DESCRIPTION      :   a MAINTENANCE ACTION file for the function, CODE
//                  :
//                  :
//                  :
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/01/05   Saint Peng      1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.setup.codeSetup.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.ProjectConstants;
import com.erp.app.setup.codeSetup.pk.CodeHdrPk;
import com.erp.app.setup.codeSetup.schema.CodeHdrSchema;
import com.erp.app.setup.codeSetup.vo.CodeHdrVo;
import com.erp.app.util.web.WebUtil;
import com.erp.framework.controller.action.SimpleMaintStyleAction;
import com.erp.framework.model.pk.SimpleBasePk;
import com.erp.framework.model.schema.TableSchema;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

/**
* A <strong>Maintenance Action</strong> is an adapter between the contents of an incoming
* HTTP request and the corresponding business logic that should be executed to
* process this request.  The controller (ActionServlet) will select an
* appropriate Action for each request.
* The main purpose for this action class is to handle the user document maintenance events
* from the web browsers.
*
* @author          Saint Peng
* @version 1.0     2006/01/05
* @since           FrameWork 1.0
*
*/
public class CodeMaintenanceAction extends SimpleMaintStyleAction {

	////////////////////////////////////////////////////////////////////////////////
	// CONSTANTS DEFINITION
	////////////////////////////////////////////////////////////////////////////////

	//public static final String ACTION_DO_SOMETHING = "actionDoSomething";
	//public static final String STATUS_DO_SOMETHING = "statusDoSomething";

    public static final int TAB_IDX_DOC = -1;
	public static final int TAB_IDX_DTL = 0;

	public static final String ActionDelDetal = "delDetail";
	public static final String ACTION_CHANGE_FOLDER_DOC = ACTION_CHANGE_FOLDER + "Hdr";
	public static final String ACTION_CHANGE_FOLDER_DTL = ACTION_CHANGE_FOLDER + "Dtl";
	public static final String ACTION_EDIT_DESC = "taEditDtlRefDesc";
	public static final String STATUS_EDIT_REMARK = "sPSet";
	public static final String ACTION_EDIT_HDRDESC = "taEditHdrRefDesc";
    private static final String POPUP_FIELD_NAME_HDRDESC = "hdrDescription";
    private static final String POPUP_FIELD_HDRDESC = "hdrDescription";
    private static final String POPUP_FIELD_NAME_DTLDESC = "Description";
    private static final String POPUP_FIELD_DTLDESC = "dtlDescription";
    private static final String STATUS_IS_DELETE_CHECKED = "checked";

	////////////////////////////////////////////////////////////////////////////////
	// GLOBAL VARIABLES DEFINITION
	////////////////////////////////////////////////////////////////////////////////



	////////////////////////////////////////////////////////////////////////////////
	// LOGICAL AND BUSINESS METHODS
	////////////////////////////////////////////////////////////////////////////////

	public ActionForward handlePageEvent(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			if (!isHandled(request) && action.equalsIgnoreCase(ACTION_ADD_DTL)) {
				processActionAddDetail(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_DEL_DTL)) {
				processActionDelDetail(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_ADD_CHARGES)) {
				processActionAddCharges(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_CHANGE_CHARGES)) {
				processActionChangeCharges(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_DEL_CHARGES)) {
				processActionDelCharges(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_INCR_REVISION)) {
				processActionIncrRevision(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_PRINT_ENG)) {
				processActionPrintEnglish(mapping, formIn, request, response, errors);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_PRINT_CHN)) {
				processActionPrintChinese(mapping, formIn, request, response, errors);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ActionDelDetal)) {
				processActionDelDetail(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_EDIT_DESC)) {
				processActionEditRemark(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_EDIT_HDRDESC )) {
				processActionEditRemark(mapping, formIn, request, response, errors);
				saveToken(request);
				setHandled(request);
//			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_APPROVE)) {
//				processActionApprove(mapping, formIn, request, response, errors);
//				saveToken(request);
//				setHandled(request);
//			} else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_DISAPPROVE)) {
//				processActionDisapprove(mapping, formIn, request, response, errors);
//				saveToken(request);
//				setHandled(request);
			}
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

	protected ActionForward processOtherStatus(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response,
		ActionErrors errors, String rb_status) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			if (rb_status.equalsIgnoreCase(STATUS_EDIT_REMARK)) {
				return processStatusEditRemark(mapping,  formIn,  request, response,  errors,  rb_status);
			}
		} catch (Exception e) {
			Logger.log(this, e);
		}

		return actionForward;
	}

	//uncomment the following code and implement the method if necessary

	protected ActionForward processActionEditRemark(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
//		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);
		String action = CommonUtil.nullToString(form.getPageEvent());

		try{
			if(action.equalsIgnoreCase(ACTION_EDIT_DESC)){
				session.removeAttribute(ProjectConstants.SESSION_SELECT_REMARK_TEXT_PARAMETERS);

				 String field = POPUP_FIELD_DTLDESC;
		         String fieldName = POPUP_FIELD_NAME_DTLDESC;
		         String fieldValue = "";
		         String eventSrc = form.getPageEventSrc();

		         TableSchema ts = form.getTs();
		         TableSchema[] childTsArray = form.getChildTs();
				 TableSchema dtlTs = childTsArray[CodeMaintenanceAction.TAB_IDX_DTL];

		         ArrayList rows = form.getMultiRows(0);
		         int idx = Integer.parseInt(eventSrc);
		         CodeDtlRow row = (CodeDtlRow) rows.get(idx);
		         fieldValue = row.getDtlRefDesc();


		         LinkedList keyList = new LinkedList();
		         keyList.add(dtlTs.getDisplayWebLabelByObjectId("LBL_SRCH_REF_MASTER_CODE"));
		         keyList.add(form.getRefMasterCode());
		         keyList.add(dtlTs.getDisplayWebLabelByObjectId("LBL_SRCH_REF_CODE"));
		         keyList.add(row.getRefCode());

		         HashMap params = new HashMap();
		         params.put(ProjectConstants.SESSION_SESSION_VALUE, getSessionSimpleMaintStatus());
		         params.put(ProjectConstants.SESSION_OPENER_PATH, getFunctionId());
		         params.put(ProjectConstants.SESSION_KEY_LIST, keyList);
		         params.put(ProjectConstants.SESSION_FIELD, field);
		         params.put(ProjectConstants.SESSION_EVENTSRC, eventSrc);
		         params.put(ProjectConstants.SESSION_EDIT_COLUMN_NAME, fieldName);
		         params.put(ProjectConstants.SESSION_EDIT_VALUE, fieldValue);

		         session.setAttribute(ProjectConstants.SESSION_SELECT_REMARK_TEXT_PARAMETERS, params);










			}else if(action.equalsIgnoreCase(ACTION_EDIT_HDRDESC)){
				session.removeAttribute(ProjectConstants.SESSION_SELECT_REMARK_TEXT_PARAMETERS);


				String field = POPUP_FIELD_HDRDESC;
		         String fieldName = POPUP_FIELD_NAME_HDRDESC;
		         String fieldValue = form.getRefDesc();
		         String eventSrc = form.getPageEventSrc();
		         TableSchema ts = form.getTs();

		         LinkedList keyList = new LinkedList();
		         keyList.add(ts.getDisplayWebLabelByObjectId("LBL_SRCH_REF_MASTER_CODE"));
		         keyList.add(form.getRefMasterCode());

		         HashMap params = new HashMap();
		         params.put(ProjectConstants.SESSION_SESSION_VALUE, getSessionSimpleMaintStatus());
		         params.put(ProjectConstants.SESSION_OPENER_PATH, getFunctionId());
		         params.put(ProjectConstants.SESSION_KEY_LIST, keyList);
		         params.put(ProjectConstants.SESSION_FIELD, field);
		         params.put(ProjectConstants.SESSION_EVENTSRC, eventSrc);
		         params.put(ProjectConstants.SESSION_EDIT_COLUMN_NAME, fieldName);
		         params.put(ProjectConstants.SESSION_EDIT_VALUE, fieldValue);

		         session.setAttribute(ProjectConstants.SESSION_SELECT_REMARK_TEXT_PARAMETERS, params);



			}
			System.out.println("You are in processActionDoSomething().");
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}


	//uncomment the following code and implement the method if necessary

	protected ActionForward processStatusEditRemark(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response,
		ActionErrors errors, String rb_status) {

		HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());
		HashMap params = (HashMap) session.getAttribute(ProjectConstants.SESSION_SELECT_REMARK_TEXT_PARAMETERS);
        session.removeAttribute(ProjectConstants.SESSION_SELECT_REMARK_TEXT_PARAMETERS);
        String editValue = (String) params.get(ProjectConstants.SESSION_EDIT_VALUE);
        String editColumnName = (String) params.get(ProjectConstants.SESSION_EDIT_COLUMN_NAME);

        CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;

		try{
			if(editColumnName.equalsIgnoreCase(POPUP_FIELD_NAME_DTLDESC)){
				String field = (String) params.get(ProjectConstants.SESSION_FIELD);
                String eventSrc = (String) params.get(ProjectConstants.SESSION_EVENTSRC);
                ArrayList rows = form.getMultiRows(0);

                int idx = Integer.parseInt(eventSrc);
                CodeDtlRow row = (CodeDtlRow) rows.get(idx);
                row.setDtlRefDesc(editValue);
                return actionForward;




			}else if(editColumnName.equalsIgnoreCase(POPUP_FIELD_NAME_HDRDESC)){
				String field = (String) params.get(ProjectConstants.SESSION_FIELD);
                String eventSrc = (String) params.get(ProjectConstants.SESSION_EVENTSRC);
                form.setRefDesc(editValue);
                return actionForward;
			}
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}


	protected ActionForward processActionAddDetail(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{


			CodeDtlRow rowToAdd = new CodeDtlRow();
			form.setCurrIdx(0);
			rowToAdd.setCompanyCode(form.getCompanyCode());
			rowToAdd.setCompanyCode(form.getCompanyCode());
			rowToAdd.setIsDelete("");
			rowToAdd.setRefMasterCode(form.getRefMasterCode());
			rowToAdd.setRefCode("");
			rowToAdd.setModeCreate();
			rowToAdd.setDtlRefStatus(ProjectConstants.GENERIC_ACTIVE);
			rowToAdd.setDtlSeq("1000");
			form.addRow(rowToAdd);
//
   		    form.setSidx(Integer.parseInt(form.getLastPageSidx()));
			//TODO: Must revise the following code.
			/*
			LinkedList criteriaList = new LinkedList();

			criteriaList.add("Quotation No.");
			criteriaList.add("INPUT");
			criteriaList.add("");

			criteriaList.add("Model No.");
			criteriaList.add("INPUT");
			criteriaList.add("");

			criteriaList.add("Product Status");
			criteriaList.add("COMBO");
			criteriaList.add("");
			criteriaList.add("t_code_dtl");
			criteriaList.add("ref_code");
			criteriaList.add("ref_desc");
			criteriaList.add("REF_MASTER_CODE = ? AND is_active = ?");
			ArrayList critValueList = new ArrayList();
			critValueList.add(ProjectConstants.CODE_ITEM_STATUS);
			critValueList.add(new BigDecimal(1));
			criteriaList.add(critValueList);
			criteriaList.add("ref_desc");
			criteriaList.add("");

			ArrayList criteriaColumnList = new ArrayList();
			criteriaColumnList.add("H.CUST_QUOT_NO");
			criteriaColumnList.add("D.ITEM_CODE");
			criteriaColumnList.add("I.STATUS");

			ArrayList rsltTextList = new ArrayList();
			rsltTextList.add("Quotation No.");
			rsltTextList.add("Model No.");
			rsltTextList.add("Description");
			rsltTextList.add("Line No.");

			ArrayList rsltColumnList = new ArrayList();
			rsltColumnList.add("H.CUST_QUOT_NO");
			rsltColumnList.add("I.ITEM_CODE");
			rsltColumnList.add("I.DESCRIPTION");
			rsltColumnList.add("D.LINE_NO");
			rsltColumnList.add("NVL(D.QTY, 0)");
			rsltColumnList.add("NVL(SUM(NVL(S.QTY, 0)) ,0)");

			Hashtable tblParams = new Hashtable();
			String fromTable = " T_ITEM_HDR I, T_CUST_QUOT_HDR H, T_CUST_QUOT_DTL D";
			String varList = "";
			ArrayList criteriaValueList = new ArrayList();
			criteriaValueList.add(ProjectConstants.STATUS_CONFIRMED);
			criteriaValueList.add(form.getCompanyCode());
			criteriaValueList.add(form.getCustCode());
			for (int i = 0; i < divisionList.size(); ++i) {
				varList += "?, ";
				DivisionGroupDtlVO divisionGroupDtlVO = (DivisionGroupDtlVO) divisionList.get(i);
				criteriaValueList.add(divisionGroupDtlVO.getDtlDivisionCode());
			}

			String whereClause = " H.COMPANY_CODE=D.COMPANY_CODE AND H.CUST_QUOT_NO=D.CUST_QUOT_NO" +
				" AND D.COMPANY_CODE=I.COMPANY_CODE AND D.ITEM_CODE=I.ITEM_CODE" +
				" AND H.STATUS=?" +
				" AND H.COMPANY_CODE=? AND H.CUST_CODE=? AND H.DIVISION IN (" +
				("".equals(varList) ? "'NULL'" : varList.substring(0, varList.length() - 2)) + ")";

			tblParams.put(ProjectConstants.SESSION_TABLE, fromTable);
			tblParams.put(ProjectConstants.SESSION_WHERE, whereClause);
			tblParams.put(ProjectConstants.SESSION_GROUPBY, " H.CUST_CODE, H.CUST_QUOT_NO, D.LINE_NO, I.ITEM_CODE, I.DESCRIPTION, D.QTY ");
			tblParams.put(ProjectConstants.SESSION_ORDERBY, " H.CUST_CODE, H.CUST_QUOT_NO, I.ITEM_CODE ");

			HashMap params = new HashMap();
			params.put(ProjectConstants.SESSION_SESSION_NAME, getSessionSimpleMaintStatus());
			params.put(ProjectConstants.SESSION_SESSION_VALUE, actionAddDetailFromCustQuot);
			params.put(ProjectConstants.SESSION_OPENER_PATH, getFunctionId());
			params.put(ProjectConstants.SESSION_EVENTSRC, form.getPageEventSrc());
			params.put(ProjectConstants.SESSION_CRITERIA_LIST, criteriaList);
			params.put(ProjectConstants.SESSION_CRITERIA_COLUMN_LIST, criteriaColumnList);
			params.put(ProjectConstants.SESSION_CRITERIA_VALUE_LIST, criteriaValueList);
			params.put(ProjectConstants.SESSION_RESULT_TEXT_LIST, rsltTextList);
			params.put(ProjectConstants.SESSION_RESULT_COLUMN_LIST, rsltColumnList);
			params.put(ProjectConstants.SESSION_TABLE_PARAMS, tblParams);
			session.setAttribute(ProjectConstants.SESSION_COMMON_SEARCH_PARAMETERS, params);
			*/

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

	protected ActionForward processActionDelDetail(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			ArrayList rows = form.getMultiRows(TAB_IDX_DTL);
			int idx = Integer.parseInt(form.getPageEventSrc());
			CodeDtlRow rowToEdit = (CodeDtlRow) rows.get(idx);
			rowToEdit.setIsDelete(STATUS_IS_DELETE_CHECKED);
			form.setRow(idx, rowToEdit);

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

	protected ActionForward processActionAddCharges(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		int originalCurrIndex = form.getCurrIdx();
		try {
			/*ArrayList rows = form.getMultiRows(TAB_IDX_CHARGES);
			CodeChargesRow rowToAdd = new CodeChargesRow();
			rowToAdd.setCompanyCode(form.getCompanyCode());
			rowToAdd.setCodeNo(form.getCodeNo());
			rowToAdd.setChargesLineNo(CommonUtil.getNextSequence(rows, "chargesLineNo"));
			rowToAdd.setIsDelete("");
			rowToAdd.setModeCreate();
			rowToAdd.setTs(new CodeChargesSchema());
			rowToAdd.setTsName("com.erp.app.setup.codeSetup.schema.CodeChargesSchema");
			form.addRow(rowToAdd);*/
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		} finally {
			form.setCurrIdx(originalCurrIndex);
		}

		return actionForward;
	}

	protected ActionForward processActionChangeCharges(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
		/*
			ArrayList rows = form.getMultiRows(TAB_IDX_CHARGES);
			int idx = Integer.parseInt(form.getPageEventSrc());
			CodeChargesRow rowToEdit = (CodeChargesRow) rows.get(idx);
			String chargesDesc = "";
			ArrayList chargesCodeList = form.getChargesCodeList();
			for (int i = 1; i < chargesCodeList.size(); ++i) {
			CodeDtlVO codeDtlVO = (CodeDtlVO) chargesCodeList.get(i);
				if (codeDtlVO.getRefCode().equals(CommonUtil.nullToString(rowToEdit.getChargesChargesCode()))) {
					chargesDesc = codeDtlVO.getDtlRefDesc();
					break;
				}
			}
			rowToEdit.setChargesChargesDesc(chargesDesc);
			form.setRow(idx, rowToEdit);
		*/
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

	protected ActionForward processActionDelCharges(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		int originalCurrIndex = form.getCurrIdx();
		try {
			/*ArrayList rows = form.getMultiRows(TAB_IDX_CHARGES);
			int idx = Integer.parseInt(form.getPageEventSrc());
			CodeChargesRow rowToEdit = (CodeChargesRow) rows.get(idx);
			rowToEdit.setIsDelete("checked");
			form.setRow(idx, rowToEdit);*/
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

	protected ActionForward processActionPrintEnglish(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			/*response.setContentType("application/pdf");
			response.setHeader("Content-Disposition", "attachment;filename=\"CODE_" + form.getCodeNo() +  ".pdf\"");
			response.setHeader("Cache-control", "private");
			response.setHeader("Pragma", null);
			response.setStatus(HttpServletResponse.SC_OK);
*/
//			OutputStream out = response.getOutputStream();
//			CodePrint printer = new CodePrint();
//			Servlet servlet = this.getServlet();
//			ByteArrayOutputStream baos = printer.getReportPdf(mapping, formIn, request, response, errors, PRINT_ENGLISH);
//			out.write(baos.toByteArray());
//			out.close();
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return null;
	}

	protected ActionForward processActionPrintChinese(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			/*response.setContentType("application/pdf");
			response.setHeader("Content-Disposition", "attachment;filename=\"CODE_" + form.getCodeNo() +  ".pdf\"");
			response.setHeader("Cache-control", "private");
			response.setHeader("Pragma", null);
			response.setStatus(HttpServletResponse.SC_OK);*/

//			OutputStream out = response.getOutputStream();
//			CodePrint printer = new CodePrint();
//			Servlet servlet = this.getServlet();
//			ByteArrayOutputStream baos = printer.getReportPdf(mapping, formIn, request, response, errors, PRINT_CHINESE);
//			out.write(baos.toByteArray());
//			out.close();
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return null;
	}

	protected ActionForward processActionIncrRevision(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			/*SimpleDateFormat sdf = new SimpleDateFormat(CommonUtil.INPUT_DATE_FORMAT, CommonUtil.DEFAULT_LOCALE);
			java.util.Date today = Calendar.getInstance().getTime();
			int revNo = 0;
			if ((form.getRevisionNo() != null) && (!(form.getRevisionNo().trim().equals("")))) {
				revNo = Integer.parseInt(form.getRevisionNo());
			} else {
				revNo = 0;
			}
			form.setRevisionNo(String.valueOf(revNo + 1));
			form.setRevisionDate(sdf.format(today));*/
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

/*
	protected ActionForward processActionSubmit(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			System.out.println("You are in processActionSubmit().");
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

*/
/*
	protected ActionForward processActionConfirm(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			System.out.println("You are in processActionConfirm().");
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

*/
/*
	protected ActionForward processActionApprove(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			System.out.println("You are in processActionApprove().");
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

*/
/*
	protected ActionForward processActionDisapprove(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			System.out.println("You are in processActionDisapprove().");
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

*/
	////////////////////////////////////////////////////////////////////////////////
	// END OF LOGICAL AND BUSINESS METHODS
	////////////////////////////////////////////////////////////////////////////////


	////////////////////////////////////////////////////////////////////////////////
	// OVERRIDES PARENT'S OPTIONAL METHODS
	////////////////////////////////////////////////////////////////////////////////

	protected void initAction(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initAction(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void initForm(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initForm(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void initPage(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initPage(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeCreate(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
			form.setCompanyCode(WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_CODE_SETUP));
			form.setTs(new CodeHdrSchema());
			form.setTsName("com.erp.app.setup.codeSetup.schema.CodeHdrSchema");

//			form.setDcInd(GENERIC_NO);
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeSave(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterSave(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeEdit(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterEdit(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeDelete(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterDelete(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeRefresh(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterRefresh(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	public String getSessionMaintStatus() {

		return getSessionSimpleMaintStatus();
	}

	public String getSessionMaintPk() {

		return getSessionSimpleMaintPk();
	}

	public String getStrutsId() {

		return getFunctionId();
	}

	protected String getSimpleSrchMenuId() {

		//TODO: Add the following line to ProjectMenuConstants.java
		//public static final String MOD_CODE = "MOD_CODE";
		return ProjectConstants.MOD_CODE_SETUP;
	}

	////////////////////////////////////////////////////////////////////////////////
	// END OF OPTIONAL METHODS
	////////////////////////////////////////////////////////////////////////////////


	////////////////////////////////////////////////////////////////////////////////
	// IMPLEMENTS PARENT'S ABSTRACT METHODS
	////////////////////////////////////////////////////////////////////////////////

	protected String getModuleName(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request,HttpServletResponse response) {

		//TODO: Add the following line to ProjectMenuConstants.java
		//public static final String MOD_CODE = "MOD_CODE";
		return ProjectConstants.MOD_CODE_SETUP;
	}

	protected String getFunctionId() {

		//struts-config xxxxx.do
		return "codeMaintenance.do";
	}

	protected Class getMasterFormClass() {

		//the corresponding form class
		return CodeMaintenanceForm.class;
	}

	protected Class getMasterVOClass() {

		//corresponding master vo class
		return CodeHdrVo.class;
	}

	protected String getMasterFormSessionName() {

		return "codeMaintenanceForm";
	}

	protected Class[] getChildRowClass() {

		Class[] childRowClass = new Class[1];

		childRowClass[0] = com.erp.app.setup.codeSetup.web.CodeDtlRow.class;

		return childRowClass;
	}

	protected String[] getFolderChildIdxMapping() {

		String[] folderChildIdx = new String[2];

		folderChildIdx[0] = String.valueOf(TAB_IDX_DTL);
		folderChildIdx[1] = String.valueOf(TAB_IDX_DTL);

		return folderChildIdx;
	}

	protected SimpleBasePk getPk(ActionForm formIn, HttpServletRequest request) {

		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		CodeHdrPk pk = null;
		HttpSession session = request.getSession(false);

		//TODO: Add the following line to ProjectSecurityConstants.java
		//public static final String SP_SHARE_CODE = "SP_SHARE_CODE";
		String companyCode = WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_CODE_SETUP);

//		edit the following with appropriate form field names
		pk = new CodeHdrPk(companyCode, form.getRefMasterCode());
		return pk;
	}

	protected void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
		HttpServletResponse response, ActionErrors errors){

		CodeMaintenanceForm form = (CodeMaintenanceForm) formIn;
		form.setFormType(ProjectConstants.FORM_TYPE_MAINT);
	}

	////////////////////////////////////////////////////////////////////////////////
	// END OF ABSTRACT METHODS
	////////////////////////////////////////////////////////////////////////////////
}
